import React from 'react'
import PureRenderMixin from 'react-addons-pure-render-mixin'
import { getOrderListData,postComment } from '../../../fetch/user/orderlist'
import OrderListComponet from '../../../components/OrderList';

import { orderListMock } from '../../../fetch/staticMock/user';//静态假数据

import './style.less'

class OrderList extends React.Component {
    constructor(props, context) {
        super(props, context);
        this.shouldComponentUpdate = PureRenderMixin.shouldComponentUpdate.bind(this);
        this.state={
            data:[]
        }
    }
    render() {
        return (
            <div className="order-list-container">
                <h2>你的订单</h2>
                {
                    this.state.data.length
                    ? <OrderListComponet submitComment={this.submitComment.bind(this)} data={this.state.data}/>
                    : <div>loading</div>
                }
            </div>
        )
    }
    componentDidMount(){
        //获取订单消息
        const username=this.props.username;
        if(username){
            this.loadOrderList(username)
        }
    }
    //获取列表数据
    loadOrderList(username){
        // const result=getOrderListData(username);
        // result.then(res=>{
        //     return res.json()
        // }).then( json=>{
        //     console.log(json);
        //     this.setState({
        //         data:json
        //     })
        // } ).catch(err=>{
        //     console.log(err)
        // });

          //模拟静态假数据
          
        function timerHandle(orderListMock){
            const data=orderListMock;
            this.setState({
                data
            })
        }
        setTimeout(timerHandle.bind(this,orderListMock),150);

    }
    // 提交评价
    submitComment(id , value ,callback){
        // const result=postComment(id,value);
        // result.then(res=>{
        //     return res.json()
        // }).then(json => {
        //     if(json.errno === 0 ){
        //         //已经评价，修改状态
        //         callback()
        //     }
        // });

        //模拟静态假数据 登陆成功
        callback();
        

    }
}

// 使用 require.ensure 异步加载，还不支持 ES6 的 export
export default OrderList